<?php

/**
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 */

if (!defined('IN_ECS'))
{
    die('Hacking attempt');
}
$cron_lang = ROOT_PATH . 'languages/' .$GLOBALS['_CFG']['lang']. '/cron/auto_received.php';
if (file_exists($cron_lang))
{
    global $_LANG;

    include_once($cron_lang);
}

/* 模块的基本信息 */
if (isset($set_modules) && $set_modules == TRUE)
{
    $i = isset($modules) ? count($modules) : 0;

    /* 代码 */
    $modules[$i]['code']    = basename(__FILE__, '.php');

    /* 描述对应的语言项 */
    $modules[$i]['desc']    = 'ar_desc';

    /* 作者 */
    $modules[$i]['author']  = 'xie';

    /* 网址 */
    $modules[$i]['website'] = '';

    /* 版本号 */
    $modules[$i]['version'] = '1.0.0';

    /* 配置信息 */
    $modules[$i]['config']  = '';

    return;
}
require_once(ROOT_PATH . '/includes/lib_order.php');
require_once(ROOT_PATH . '/includes/lib_common.php');

$time = local_strtotime('-1 week');
$where =  "WHERE oi.order_status=".OS_CONFIRMED;
$where .= " AND oi.pay_status=".PS_PAYED;
$where .= " AND oi.push_status=".PUS_PUSHED;
$where .= " AND oi.shipping_status =".SS_SIGN;	//已签收
$where .= " AND oi.sign_time < ".$time;
$where .= " AND og.suppliers_id=1"; //威时管理的仓库

// $limit = " LIMIT ".$num;

$orderBy = " ORDER BY oi.sign_time DESC ";
$groupBy = " GROUP BY oi.order_sn ";

$sql = "SELECT oi.* FROM ".
		$GLOBALS['ecs']->table('order_info')." AS oi ".
		" JOIN ".$GLOBALS['ecs']->table('order_goods')." AS og ON og.order_id=oi.order_id ".
		$where.$groupBy.$orderBy;

$orders = $GLOBALS['db']->getAll($sql);
// print_r($orders);

if (empty($orders)) return;

foreach ($orders as $key=>$v){
	
	$arr['shipping_status'] = SS_RECEIVED;
	update_order($v['order_id'], $arr);
	
	/* 记录log */
	order_action($v['order_sn'], $v['order_status'], SS_RECEIVED, $v['pay_status'], '','定时任务');
}









?>